public class ListOfTypes {      

        private int size;
        private Type[] Types; 
        private int nbTypes;
        
        public ListOfTypes (int n) {         
                
                nbTypes = 0;
                size = n;
                Types =  new Type[n];
                        }
        
        
        public boolean full () {
                return nbTypes == size;
                }
        public boolean empty () {
                return nbTypes == 0;
                }
        
        public Type retrieve (int nbOfType) {
                        return Types[nbOfType];
                }
                
                
   
  public boolean addType (Type t) {
                        
           if (getNbTypes() < getSize()) {
                  Types[getNbTypes()] = t;
                  nbTypes++;
                  return true;
            }
           else
                  return false;
  }

        public Type addTypeByName (String name) { // I added this method 
            if (getNbTypes() < getSize()) {       // because some times in the parser I need to add a type with specific name 
            	Type t = new Type(name);
                    Types[getNbTypes()] = t;
                    nbTypes++;
                            return t;
            }
            else
                    return null;
    }

        
  public boolean removeType (String nameOfType) {
        for (int i =0 ; i < nbTypes ; i++) {
           if (Types[i].getName().equals(nameOfType) ){
                for(int p = i+1 ; p < nbTypes ; p++){
                    Types[p-1] = Types[p];
                }
                nbTypes--;      
                return true ;
           }        
        }
        return false ;
  }
                
                public int findType(String nameOfType){
                        for(int i = 0 ; i < getSize() ; i++){
                                if(Types[i].getName().equals(nameOfType)){
                                        return i ;
                                }
                        }
                        return -1  ;     
                }
                
                public Type findType2(String nameOfType){  // I add this method because sometimes I need to find specific type and 
                    for(int i = 0 ; i < getNbTypes() ; i++){// return an object to modify on that object
                            if(Types[i].getName().equals(nameOfType)){
                                    return Types[i] ;
                            }
                    }
                    return null  ;    
            }


      public void display(){
    	  if(nbTypes == 0){
    		  System.out.println("============================================");
    		  System.out.println("There is no type");
    		  System.out.println("============================================");
    	  }
    	  else{
        System.out.println("============================================");
        System.out.println("the size of the ListOfTypes array is : " + getSize()  );
        for (int i = 0 ; i < getNbTypes() ; i++ ){
            System.out.println("the index of element in the array is : " + i ); 
             Types[i].display();
            System.out.println("============================================");
        }
        System.out.println("============================================");
    	  }
      }    
      
      public void displayTypesOfPredicates(){ // I added this method to display the types(parameter) of the predicates
    	  if(getNbTypes() == 0)
    		  System.out.println("There is no type"); 
    	  else{
        for (int i = 0 ; i < getNbTypes() ; i++ )
             Types[i].display2();
        
    	  }
      }   
    	  
      

                        public int getSize() {
                                return size;
                        }
                        
                        public Type[] getTypes() {
                                return Types;
                        }

                        public int getNbTypes() {
                                return nbTypes;
                        }


        
                        public void setSize(int size) {
         if(size > nbTypes)
                                this.size = size;
            else System.out.println("you write size small than number of element , please rewrite the size");
                        }


                        public void setTypes(Type[] types) {
                                Types = types;
                        }


                  
                  
        
        
}
